package ch.exploadingelephants.model;

import java.util.Iterator;

import ch.exploadingelephants.graph.DotString;

/**
 * @author Sandro De Zanet
 * 
 */
public class DotStringGenerator implements Iterator<DotString> {
    private int currentSize;
    private int currentIndex;
    private final int size;

    /**
     * @param i
     */
    public DotStringGenerator(int size) {
	this.size = size;
	this.currentIndex = 0;
	this.currentSize = 0;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.util.Iterator#hasNext()
     */
    public boolean hasNext() {
	return currentSize <= size;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.util.Iterator#next()
     */
    public DotString next() {
	String s = "";
	for (int i = 0; i < currentSize; i++) {
	    if ((currentIndex / (int) (Math.pow(2, i))) % 2 == 0) {
		s += "r";
	    } else {
		s += "b";
	    }
	}

	currentIndex++;
	if (currentIndex >= (int) Math.pow(2, currentSize)) {
	    currentSize++;
	    currentIndex = 0;
	}

	return new DotString(s);
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.util.Iterator#remove()
     */
    public void remove() {
	// TODO Auto-generated method stub

    }

}
